﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Drawing;

namespace Interface
{
    /// <summary>
    /// Interaction logic for VerSucursal.xaml
    /// </summary>
    public partial class VerSucursal : UserControl
    {
        public VerSucursal()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                label7.Content = Proceso.GestorSucursal.cantidadSucursal1(textBox1.Text).ToString();
            }
            catch (Exception ex)
            {

            }
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                label8.Content = Proceso.GestorSucursal.cantidadSucursal2(textBox1.Text).ToString();
            }
            catch (Exception ex)
            {

            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog o = new OpenFileDialog();
            if (o.ShowDialog() == true)
            {
                byte[] bytes = File.ReadAllBytes(o.FileName);
                ArrayList code = new ArrayList();
                int iScan = 100;
                TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));
                try
                {
                    Bitmap bitmap1 = (Bitmap)tc.ConvertFrom(bytes);

                    BarcodeImaging.FullScanPage(ref code, bitmap1, iScan);
                    string message = "";
                    if (code.Count > 0)
                    {
                        foreach (var op in code)
                        {
                            message += op.ToString();
                        }
                        textBox1.Text = message;
                    }
                    else
                        message = "No hay codigo de barras";
                    MessageBox.Show(message);
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Elija formato de imagen");
                }
            }
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
              OpenFileDialog o = new OpenFileDialog();
              if (o.ShowDialog() == true)
              {
                  byte[] bytes = File.ReadAllBytes(o.FileName);
                  ArrayList code = new ArrayList();
                  int iScan = 100;
                  TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));
                  try
                  {
                      Bitmap bitmap1 = (Bitmap)tc.ConvertFrom(bytes);

                      BarcodeImaging.FullScanPage(ref code, bitmap1, iScan);
                      string message = "";
                      if (code.Count > 0)
                      {
                          foreach (var op in code)
                          {
                              message += op.ToString();
                          }
                          textBox2.Text = message;
                      }
                      else
                          message = "No hay codigo de barras";
                      MessageBox.Show(message);
                  }
                  catch (ArgumentException)
                  {
                      MessageBox.Show("Elija formato de imagen");
                  }
              }
        }
    }
}
